package br.com.android.serialization.api;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Comparator;

public class BaseVO implements Serializable {
	private static final long serialVersionUID = -7992388483334172636L;

	private Integer id;

	public void clear() {
		// TODO 
	}
	
	private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
		ois.defaultReadObject();
	}

	private void writeObject(ObjectOutputStream oos) throws IOException {
		oos.defaultWriteObject();
	}
	
	public <T extends BaseVO> boolean equals(T outro){
    	try {
			if (outro != null && outro.getId() == this.getId())
				return true;
		} catch (Exception e) {
			return false;
		}
		return false;
    }
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("BaseVO [");
		if (id != null)
			builder.append("id=").append(id).append(", ");
		if (COMPARATOR != null)
			builder.append("COMPARATOR=").append(COMPARATOR);
		builder.append("]");
		return builder.toString();
	}

	public final Comparator<BaseVO> COMPARATOR = new Comparator<BaseVO>() {
		public int compare(BaseVO tipo1, BaseVO tipo2) {
			return tipo1.getId() < tipo2.getId() ? -1 : (tipo1.getId() > tipo2.getId() ? 1 : 0);
		}
	};
	
	/**
	 * Gets Sets
	 */
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
}
